package com.example.permissionserviceconsumer.controller;

import com.myprojects.common.pojo.Role;
import com.example.permissionserviceconsumer.service.FeignRoleService;
import com.myprojects.common.dto.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "/role-curd")
public class RoleController {

    @Autowired
    FeignRoleService feignRoleService;

    /**
     * 该方法用于分页查询所有的用户信息(非员工)
     */
    @RequestMapping(value = "/roles",method = RequestMethod.GET)
    @ResponseBody
    public Msg selectRolesByPageNum(
            @RequestParam(value = "pn",defaultValue = "1") Integer pageNum){//普通
        return feignRoleService.selectRolesByPageNum(pageNum);
    }

    /**
     * 该方法用于保存角色
     */
    @RequestMapping(value = "/roles",method = RequestMethod.POST)
    @ResponseBody
    public Msg saveRole(@RequestBody Role role){
        return feignRoleService.saveRole(role);
    }

    /**
     * 该方法用于删除角色
     */
    @RequestMapping(value = "/roles",method = RequestMethod.DELETE)
    @ResponseBody
    public Msg deleteRole(@RequestParam(value = "id") Integer id){
        return feignRoleService.deleteRole(id);
    }

    /**
     * 该方法用于更新角色
     */
    @RequestMapping(value = "/roles",method = RequestMethod.PUT)
    @ResponseBody
    public Msg updateRole(@RequestBody Role role){
        return feignRoleService.updateRole(role);
    }

    /**
     * 该方法用于获取所有的资源信息
     */
    @RequestMapping(value = "/resources",method = RequestMethod.GET)
    @ResponseBody
    public Msg getAllResources(){
        return feignRoleService.getAllResources();
    }

}
